<?php

    include("conn.php");

    $t1 = microtime(true);

    $username= G("username"); ///  

    $password=G("password");

	$nickname= G("nickname");

    $sex=G("sex");

    //   http://192.168.1.100/s/reg.php?username=asdf&password=123&nickname=jb&sex=1
    
	//参数验证
    if($username==NULL || $password==NULL ||  $nickname==NULL ||  $sex  ==NULL  ){
		
		$jb->code=-1; 
		$jb->test= "no param"; 
		die( json_encode($jb) );  
    }

 
	// 注册账号
	 $s2="insert into  tb_user   (createTime,sex,nickName,userName,password) values ( now(),  $sex , '$nickname' ,'$username' ,'$password'  ); ";
		
		//echo $s2;

	$jb->code=0;
	$jb->test= "reg err";
		
	//执行
	mysql_query($s2, $conn)  or die(   json_encode($jb) );

  
		
	//  查询注册 后的用户uid
	$strsql="select uid from tb_user where  userName='$username'  "; 

	 
	$result=mysql_query($strsql, $conn);
	   
	$rows=mysql_fetch_array($result);
	if(!$rows)
	{
		 
		//!!!不存在， 上面的注册失败！！

		$jb->code=0;
		$jb->test= "注册失败!";
		json_encode($jb);
 
		 
	}else{
		 
		 $jb->code=0;
		$jb->test= " err !";

		//添加默认好友分组
		 $strsql="insert  into tb_friendgroup (groupName ,uid   ) values( '我的好友' ,  $rows[0] ) ";
		 mysql_query($strsql, $conn)   or die(  json_encode($jb) );

		 $strsql="insert  into tb_friendgroup (groupName ,uid   ) values( '陌生人' ,  $rows[0] ) "; 
		 mysql_query($strsql, $conn)   or die(  json_encode($jb) );

		 $strsql="insert  into tb_friendgroup (groupName ,uid   ) values( '黑名单' ,  $rows[0] ) "; 
		 mysql_query($strsql, $conn)   or die(  json_encode($jb) );
  
	}

 
		$t2 = microtime(true);
       
	
		$jb->code=1;
        $jb->test=  "reg ok 耗时".round($t2-$t1,6)."秒";
       
        echo json_encode($jb);



		mysql_close();
?>
